package ym.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ym.pojo.HouseImg;
import ym.service.HouseImgService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 房源图片
 */
@CrossOrigin
@RestController
@RequestMapping("/front/houseImg")
public class FrontHouseImgCon {
    @DubboReference
    private HouseImgService houseImgService;
    /**
     * 根据房源查询所有
     *
     * @param houseId
     * @return
     */
    @GetMapping("/findAllByHouseId")
    public BaseResult findAllByHouseId(Integer houseId) {
        List<HouseImg> all = houseImgService.findAllByHouseId(houseId);
        return BaseResult.ok(all);
    }

    /**
     * 根据房源分页查询
     *
     * @param houseId
     * @param search
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/searchByHouseId")
    public BaseResult searchByHouseId(Integer houseId, String search, int page, int size) {
        Page<HouseImg> houseImgPage = houseImgService.searchByHouseId(houseId, search, page, size);
        return BaseResult.ok(houseImgPage);
    }
}
